<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- Meta, title, CSS, favicons, etc. -->
<meta charset="utf-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>随便打TCS系统</title>
<script type="text/javascript" src="<%=basePath%>js/initPage.js"></script>
<!-- Bootstrap -->
<link href="<%=basePath%>vendors/bootstrap/dist/css/bootstrap.min.css"
	rel="stylesheet">
<!-- Font Awesome -->
<link
	href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"
	rel="stylesheet">
<!-- NProgress -->
<link href="<%=basePath%>vendors/nprogress/nprogress.css"
	rel="stylesheet">
<!-- iCheck -->
<link href="<%=basePath%>vendors/iCheck/skins/flat/green.css"
	rel="stylesheet">

<!-- bootstrap-progressbar -->
<link
	href="<%=basePath%>vendors/bootstrap-progressbar/css/bootstrap-progressbar-3.3.4.min.css"
	rel="stylesheet">
<!-- JQVMap -->
<link href="<%=basePath%>vendors/jqvmap/dist/jqvmap.min.css"
	rel="stylesheet" />
<!-- bootstrap-daterangepicker -->
<link
	href="<%=basePath%>vendors/bootstrap-daterangepicker/daterangepicker.css"
	rel="stylesheet">

<!-- Custom Theme Style -->
<link href="<%=basePath%>build/css/custom.min.css" rel="stylesheet">
</head>

<body class="nav-md">
	<div class="container body">
		<div class="main_container">
			<div class="col-md-3 left_col">
				<div class="left_col scroll-view">


					<div class="clearfix"></div>

					<br />

				</div>
			</div>

			<!-- page content -->
			<div class="right_col" role="main">
				<div class="">
					<div class="page-title">
						<div class="row tile_count">

						<div class="title_left"></div>
						<div class="x_content"></div>
						</div>
					</div>

					<input type="hidden" name="parent" id="userid"
						value="${userid}" />

					<div class="x_panel">

						<div class="x_content">
							一级(一店)业绩<button type="submit" class="btn btn-default" onclick="update('${subscribers.id}',1,1)">添加</button>
							二级(二店)业绩<button type="submit" class="btn btn-default" onclick="update('${subscribers.id}',1,2)">添加</button>
							三级(三店)业绩<button type="submit" class="btn btn-default" onclick="update('${subscribers.id}',1,3)">添加</button>
							<table id="datatable" class="table table-striped table-bordered">
								<thead>
									<tr>
										<th>账号</th>
										<c:if test="${adminUsergrade < 2 }">
										    <th>姓名</th>
										</c:if>
										<th>状态</th>
										<c:if test="${adminUsergrade < 2  }">
											<th>所属OEM</th>
											<th>所属商家</th>
										</c:if>
										<th>注册时间/过期时间</th>
									</tr>
								</thead>
								<tbody>
									<c:forEach items="${list}" var="s" varStatus="z">

										<tr>
											<td><c:if test="${s.subMobile == null }">
													<span>该数据异常</span>
												</c:if> <c:if test="${s.subMobile != null }">
													<span>${s.subMobile}</span>
												</c:if></td>
											<c:if test="${adminUsergrade < 2 }">
											    <td>${s.subUsername}</td>
											</c:if>
											<td><c:if test="${s.subDatastatus == true }">
													<span>可用</span>
												</c:if> <c:if test="${s.subDatastatus == false }">
													<span>冻结</span>
												</c:if></td>
											<c:if test="${adminUsergrade < 2  }">
												<td>${s.subParentid}</td>
												<td>${s.subShopid}</td>
											</c:if>
											<td><fmt:formatDate value="${s.subCreatetime}" type="date"
													pattern="yyyy-MM-dd" /> -- <fmt:formatDate
													value="${s.subEndtime}" type="date" pattern="yyyy-MM-dd " /></td>
										</tr>
									</c:forEach>
								</tbody>
							</table>
						</div>
					</div>
					<div class="clearfix"></div>
					<br />
				</div>
				<div style="width: 100%; text-align: center;">
					<div id='page'></div>
				</div>
			</div>
			<!-- /page content -->


		</div>
	</div>

	<script>
		/**
		 * 纯粹的JS分页插件，代码缺点：JS操作DOM冗余太多，太繁琐
		 */
		pageUtil.initPage('page', {
			totalCount : ${totlenum}, //总页数，一般从回调函数中获取。如果没有数据则默认为1页
			curPage : ${curPage}, //初始化时的默认选中页，默认第一页。如果所填范围溢出或者非数字或者数字字符串，则默认第一页
			showCount : 9, //分页栏显示的数量
			pageSizeList : [ 10 ], //自定义分页数，默认[5,10,15,20,50]
			defaultPageSize : 10, //默认选中的分页数,默认选中第一个。如果未匹配到数组或者默认数组中，则也为第一个
			isJump : true, //是否包含跳转功能，默认false
			isPageNum : true, //是否显示分页下拉选择，默认false
			isPN : true, //是否显示上一页和下一面，默认true
			isFL : true, //是否显示首页和末页，默认true
			jump : function(curPage, pageSize) { //跳转功能回调，传递回来2个参数，当前页和每页大小。如果没有设置分页下拉，则第二个参数永远为0。这里的this被指定为一个空对象，如果回调中需用到this请自行使用bind方法
				selectOEM(curPage);
			},
		});
	</script>

	<script src="<%=basePath%>vendors/jquery/dist/jquery.min.js"></script>
	<script type="text/javascript">
		function selectOEM(curPage) {
			var userid = $("#userid").val();
			location.href = "selectZXRewards?userid=" + userid +
				"&curPage=" + curPage;
		}
		
		// ajax 对象
		function ajaxObject() {
			var xmlHttp;
			try {
				// Firefox, Opera 8.0+, Safari
				xmlHttp = new XMLHttpRequest();
			} catch (e) {
				// Internet Explorer
				try {
					xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) {
					try {
						xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
					} catch (e) {
						alert("您的浏览器不支持AJAX！");
						return false;
					}
				}
			}
			return xmlHttp;
		}

		var newId = "";
		function update(id,type,share) {
			switch (share) {
				case 1:
					shareRegisterOne(id, type);
					break;
				case 2:
					shareRegisterTwo(id, type);
					break;
				case 3:
					shareRegisterThree(id, type);
					break;
			}
		}

		function getPrefix() {
			var prefixArray = ["130", "131", "132", "133", "135", "137", "138", "170", "187", "189"];
			var i = parseInt(10 * Math.random());
			var prefix = prefixArray[i];
			for (var j = 0; j < 8; j++) {
				prefix = prefix + Math.floor(Math.random() * 10);
			}
			return prefix;
		}

		function shareRegisterOne(id,type){
			var prefix = getPrefix();
			$.ajax({
				type : 'POST',
				url : 'http://shuntong.sbdznkj.com/SbdVoip/login/shareRegister',
				async : false ,
				data : {
					Mobile : prefix,
					ShareId : id,
					UserName : "jsj",
					type : 1
				},
				success : function(date) {
					if (date.errorCode == 2000){
						updateCardOne(date.otherJson, prefix, type);
					} else{
						alert("一级注册失败");
					}
				}
			});
		}

		function updateCardOne(id,mobile,type) {
			var d = new Date();
			d.setFullYear(d.getFullYear() + 1);  //加一年
			var endtime = d.getFullYear() + "-" + d.getMonth() + "-" +d.getDate();
			var ajax = ajaxObject();
			ajax.open("post", "updateSubscribers?id=" + id +
					"&money=" + 5000 +
					"&endtime=" + endtime +
					"&mobile=" + mobile +
					"&isyearcard=" + 1 +
					"&zxRewards=" + type, false);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.onreadystatechange = function() {
				if (ajax.readyState == 4) {
					if (ajax.status == 200) {
						var result = ajax.responseText;
						if (result == "success") {
							//请求成功
							alert("注册成功");
							selectOEM(${curPage});
						} else {
							//请求成功
							alert("注册成功");
							selectOEM(${curPage});
						}
					} else {
						//请求失败
						selectOEM(${curPage});
					}
				} else {
				}
			};
			ajax.send();
		}

		function shareRegisterTwo(id,type){
            var d = new Date();
            d.setFullYear(d.getFullYear() + 1);  //加一年
            var endtime = d.getFullYear() + "-" + d.getMonth() + "-" +d.getDate();

			var prefix = getPrefix();
			$.ajax({
				type : 'POST',
				url : 'http://shuntong.sbdznkj.com/SbdVoip/login/share',
				async : false ,
				data : {
                    mobile : prefix,
                    shareId : id,
                    userName : "jsj",
                    endtime : endtime,
					type : 1
				},
				success : function(date) {
					if (date.errorCode == 2000){
						if(date.otherJson == 2){
							updateCardTwo(date.json, prefix, type);
						}else{
							var prefix = getPrefix();
							$.ajax({
								type : 'POST',
								url : '<%=basePath%>login/share',
								async : false ,
								data : {
									mobile : prefix,
									shareId : date.json,
									userName : "jsj",
									type : 2
								},
								success : function(date) {
									if (date.errorCode == 2000){
										updateCardTwoEnd(date.json, prefix, type);
									} else{
										alert("二级注册失败");
									}
								}
							});
						}
					} else{
						alert("一级注册失败");
					}
				}
			});
		}

		function updateCardTwo(id,mobile,type) {
			var d = new Date();
			d.setFullYear(d.getFullYear() + 1);  //加一年
			var endtime = d.getFullYear() + "-" + d.getMonth() + "-" +d.getDate();
			var ajax = ajaxObject();
			ajax.open("post", "updateSubscribers?id=" + id +
					"&money=" + 5000 +
					"&endtime=" + endtime +
					"&mobile=" + mobile +
					"&isyearcard=" + 1 +
					"&zxRewards=" + type, false);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.onreadystatechange = function() {
				if (ajax.readyState == 4) {
					if (ajax.status == 200) {
						var prefix = getPrefix();
						$.ajax({
							type : 'POST',
							url : '<%=basePath%>login/share',
							async : false ,
							data : {
								mobile : prefix,
								shareId : id,
								userName : "jsj",
								type : 2
							},
							success : function(date) {
								if (date.errorCode == 2000){
									updateCardTwoEnd(date.json, prefix, type);
								} else{
									alert("二级注册失败");
								}
							}
						});
					} else {
						//请求失败
						alert("二级注册失败");
						selectOEM(${curPage});
					}
				} else {
				}
			};
			ajax.send();
		}

		function updateCardTwoEnd(id,mobile,type) {
			var d = new Date();
			d.setFullYear(d.getFullYear() + 1);  //加一年
			var endtime = d.getFullYear() + "-" + d.getMonth() + "-" +d.getDate();
			var ajax = ajaxObject();
			ajax.open("post", "updateSubscribers?id=" + id +
					"&money=" + 5000 +
					"&endtime=" + endtime +
					"&mobile=" + mobile +
					"&isyearcard=" + 1 +
					"&zxRewards=" + type, false);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.onreadystatechange = function() {
				if (ajax.readyState == 4) {
					if (ajax.status == 200) {
						var result = ajax.responseText;
						if (result == "success") {
							//请求成功
							alert("注册成功");
							selectOEM(${curPage});
						} else {
							//请求成功
							alert("注册成功");
							selectOEM(${curPage});
						}
					} else {
						//请求失败
						selectOEM(${curPage});
					}
				} else {
				}
			};
			ajax.send();
		}

		function shareRegisterThree(id,type){
			var d = new Date();
			d.setFullYear(d.getFullYear() + 1);  //加一年
			var endtime = d.getFullYear() + "-" + d.getMonth() + "-" +d.getDate();

			var prefix = getPrefix();
			$.ajax({
				type : 'POST',
				url : 'http://shuntong.sbdznkj.com/SbdVoip/login/share',
				async : false ,
				data : {
					mobile : prefix,
					shareId : id,
					userName : "jsj",
					type : 1
				},
				success : function(date) {
					if (date.errorCode == 2000){
						if (date.otherJson == 2){
							updateCardThree(date.json, prefix, type);
						} else {
							var prefix = getPrefix();
							$.ajax({
								type : 'POST',
								url : 'http://shuntong.sbdznkj.com/SbdVoip/login/share',
								async : false ,
								data : {
									mobile : prefix,
									shareId : date.json,
									userName : "jsj",
									type : 1
								},
								success : function(date) {
									if (date.errorCode == 2000){
										if (date.otherJson == 2){
											updateCardThreeAgain(date.json, prefix, type);
										} else{
											var prefix = getPrefix();
											$.ajax({
												type : 'POST',
												url : 'http://shuntong.sbdznkj.com/SbdVoip/login/share',
												async : false ,
												data : {
													mobile : prefix,
													shareId : date.json,
													userName : "jsj",
													type : 2
												},
												success : function(date) {
													if (date.errorCode == 2000){
														updateCardThreeEnd(date.json, prefix, type);
													} else{
														alert("三级注册失败");
													}
												}
											});
										}
									} else{
										alert("二级注册失败");
									}
								}
							});
						}
					} else{
						alert("一级注册失败");
					}
				}
			});
		}

		function updateCardThree(id,mobile,type) {
			var d = new Date();
			d.setFullYear(d.getFullYear() + 1);  //加一年
			var endtime = d.getFullYear() + "-" + d.getMonth() + "-" +d.getDate();
			var ajax = ajaxObject();
			ajax.open("post", "updateSubscribers?id=" + id +
					"&money=" + 5000 +
					"&endtime=" + endtime +
					"&mobile=" + mobile +
					"&isyearcard=" + 1 +
					"&zxRewards=" + type, false);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.onreadystatechange = function() {
				if (ajax.readyState == 4) {
					if (ajax.status == 200) {
						var prefix = getPrefix();
						$.ajax({
							type : 'POST',
							url : 'http://shuntong.sbdznkj.com/SbdVoip/login/share',
							async : false ,
							data : {
								mobile : prefix,
								shareId : id,
								userName : "jsj",
								type : 1
							},
							success : function(date) {
								if (date.errorCode == 2000){
									if (date.otherJson == 2){
										updateCardThreeAgain(date.json, prefix, type);
									} else{
										var prefix = getPrefix();
										$.ajax({
											type : 'POST',
											url : 'http://shuntong.sbdznkj.com/SbdVoip/login/share',
											async : false ,
											data : {
												mobile : prefix,
												shareId : date.json,
												userName : "jsj",
												type : 2
											},
											success : function(date) {
												if (date.errorCode == 2000){
													updateCardThreeEnd(date.json, prefix, type);
												} else{
													alert("三级注册失败");
												}
											}
										});
									}
								} else{
									alert("二级注册失败");
								}
							}
						});
					} else {
						//请求失败
						selectOEM(${curPage});
					}
				} else {
				}
			};
			ajax.send();
		}

		function updateCardThreeAgain(id,mobile,type) {
			var d = new Date();
			d.setFullYear(d.getFullYear() + 1);  //加一年
			var endtime = d.getFullYear() + "-" + d.getMonth() + "-" +d.getDate();
			var ajax = ajaxObject();
			ajax.open("post", "updateSubscribers?id=" + id +
					"&money=" + 5000 +
					"&endtime=" + endtime +
					"&mobile=" + mobile +
					"&isyearcard=" + 1 +
					"&zxRewards=" + type, false);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.onreadystatechange = function() {
				if (ajax.readyState == 4) {
					if (ajax.status == 200) {
						var prefix = getPrefix();
						$.ajax({
							type : 'POST',
							url : 'http://shuntong.sbdznkj.com/SbdVoip/login/share',
							async : false ,
							data : {
								mobile : prefix,
								shareId : id,
								userName : "jsj",
								type : 2
							},
							success : function(date) {
								if (date.errorCode == 2000){
									updateCardThreeEnd(date.json, prefix, type);
								} else{
									alert("三级注册失败");
								}
							}
						});
					} else {
						//请求失败
						selectOEM(${curPage});
					}
				} else {
				}
			};
			ajax.send();
		}

		function updateCardThreeEnd(id,mobile,type) {
			var d = new Date();
			d.setFullYear(d.getFullYear() + 1);  //加一年
			var endtime = d.getFullYear() + "-" + d.getMonth() + "-" +d.getDate();
			var ajax = ajaxObject();
			ajax.open("post", "updateSubscribers?id=" + id +
					"&money=" + 5000 +
					"&endtime=" + endtime +
					"&mobile=" + mobile +
					"&isyearcard=" + 1 +
					"&zxRewards=" + type, false);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.onreadystatechange = function() {
				if (ajax.readyState == 4) {
					if (ajax.status == 200) {
						var result = ajax.responseText;
						if (result == "success") {
							//请求成功
							alert("注册成功");
							selectOEM(${curPage});
						} else {
							//请求成功
							alert("注册成功");
							selectOEM(${curPage});
						}
					} else {
						//请求失败
						selectOEM(${curPage});
					}
				} else {
				}
			};
			ajax.send();
		}
	</script>
	<!-- Bootstrap -->
	<script src="<%=basePath%>vendors/bootstrap/dist/js/bootstrap.min.js"></script>
	<!-- FastClick -->
	<script src="<%=basePath%>vendors/fastclick/lib/fastclick.js"></script>
	<!-- NProgress -->
	<script src="<%=basePath%>vendors/nprogress/nprogress.js"></script>
	<!-- bootstrap-daterangepicker -->
	<script src="<%=basePath%>vendors/moment/min/moment.min.js"></script>
	<script
		src="<%=basePath%>vendors/bootstrap-daterangepicker/daterangepicker.js"></script>
	<!-- Chart.js -->
	<script src="<%=basePath%>vendors/Chart.js/dist/Chart.min.js"></script>
	<script src="<%=basePath%>build/js/custom.min.js"></script>
	<!-- iCheck -->
	<script src="<%=basePath%>vendors/iCheck/icheck.min.js">
	</script>
	<!-- bootstrap-wysiwyg -->
	<script
		src="<%=basePath%>vendors/bootstrap-wysiwyg/js/bootstrap-wysiwyg.min.js"></script>
	<script src="<%=basePath%>vendors/jquery.hotkeys/jquery.hotkeys.js"></script>
	<script src="<%=basePath%>vendors/google-code-prettify/src/prettify.js"></script>
	<!-- jQuery Tags Input -->
	<script
		src="<%=basePath%>vendors/jquery.tagsinput/src/jquery.tagsinput.js"></script>
	<!-- Switchery -->
	<script src="<%=basePath%>vendors/switchery/dist/switchery.min.js"></script>
	<!-- Select2 -->
	<script src="<%=basePath%>vendors/select2/dist/js/select2.full.min.js"></script>
	<!-- Parsley -->
	<script src="<%=basePath%>vendors/parsleyjs/dist/parsley.min.js"></script>
	<!-- Autosize -->
	<script src="<%=basePath%>vendors/autosize/dist/autosize.min.js"></script>
	<!-- jQuery autocomplete -->
	<script
		src="<%=basePath%>vendors/devbridge-autocomplete/dist/jquery.autocomplete.min.js"></script>
	<!-- starrr -->
	<script src="<%=basePath%>vendors/starrr/dist/starrr.js"></script>
	<!-- layui -->
	<script src="<%=basePath%>vendors/layui/layui.js"></script>
	<!-- Custom Theme Scripts -->
	<!--  <script src="<%=basePath%>build/js/custom.min.js"></script>-->

</body>
</html>